
public class ResponseMessage {
	private int moveReq, moveReal;
	private int rotateReq, rotateReal;
	private boolean reboot = false;
	private int nScan;
	private int scanValue[];

	public ResponseMessage(int mReq, int mReal, int rReq, int rReal, int n,
			int scan[], boolean r) {
		moveReq = mReq;
		moveReal = mReal;
		rotateReq = rReq;
		rotateReal = rReal;
		nScan = n;
		scanValue = scan;
		reboot = r;
	}

	public int getMoveReal() {
		return moveReal;
	}

	public int getMoveReq() {
		return moveReq;
	}

	public boolean notMoveEqual() {
		return moveReq == moveReal;
	}

	public int getRotateReal() {
		return rotateReal;
	}

	public int getRotateReq() {
		return rotateReq;
	}

	public boolean notRotateEqual() {
		return rotateReq == rotateReal;
	}

	public int getNumScan() {
		return nScan;
	}

	public int getScanValueN(int n) {
		return scanValue[n];
	}

	public String getXML() {
		StringBuilder reply = new StringBuilder();
		reply.append("<r2s>");
		
		if (moveReq != 0)
			reply.append("<move req=\"" + moveReq + "\" real=\"" + moveReal + "\"/>");
		if (rotateReq != 0)
			reply.append("<rotate req=\"" + rotateReq + "\" real=\"" + rotateReal + "\"/>");
		if (nScan != 0) {
			reply.append("<scan n=\"" + nScan + "\" ");
			for (int i=1;i<=nScan;i++){
				reply.append("n"+i+"=\"" + scanValue[i-1] + "\" ");
			}
			reply.append("/>");
		}
		if (reboot)
			reply.append("<reboot/>");
		
		reply.append("</r2s>");
		return reply.toString();
	}

	
	public String toString() {
		StringBuilder result = new StringBuilder();
		if (notMoveEqual()) {
			result.append("\tWas requested to drive " + moveReq + " but drove " + moveReal + ".\n");
		} else {
			result.append("\tDrove "+moveReal+"cm.\n");
		}
		if (notRotateEqual()) {
			result.append("\tWas requested to rotate " + rotateReq + " but rotated " + rotateReal + ".\n");
		} else {
			result.append("\tRotated "+rotateReal+"cm.\n");
		}
		result.append("\tScanned in " +nScan + "direction: \n");
		for(int i = 0;i<nScan;i++){
			result.append("\t\tResult " + (i+1) + ": " + scanValue[i] + "\n");
		}
		if (reboot){
			result.append("Robot rebooted!\n");
		}
		return result.toString();
	}
}
